package com.clqteam.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.clqteam.model.Employee;
import com.clqteam.service.removeShsService;
import com.clqteam.serviceimpl.removeShsServiceImpl;

public class removeShsController extends HttpServlet{
	removeShsService re = new removeShsServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//获取系统时间
   	 Date date=new Date();
   	 SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   	 String drTime=format.format(date);
   	 
   	 
		String pid=req.getParameter("pId");
		int n  = Integer.parseInt(pid);
		
		
		
		 //写入日志
      	 HttpSession session = req.getSession();
      	 Employee emp = (Employee) session.getAttribute("employee");
      	 String eName = emp.geteName();
      	 int eId = emp.geteId();
      	 String ss = re.getProductInfoByPid(n);

      	StringBuffer drInfos = new StringBuffer();
      	drInfos.append("用户");
  		drInfos.append(eName);
  		drInfos.append("把编号为");
  		drInfos.append(pid);
  		drInfos.append("的商品的库存信息删除了,商品的详细信息为:");
  		drInfos.append(ss);
  		String drInfo = drInfos.toString();
  		re.setdrInfo(drInfo, drTime, eId, eName);
      	
  		
		//删除订单信息
        int oId = re.getOidByPid(n);
        re.removeAccountInfo(oId);
        re.removeOrderInfo(oId);
        re.removeOrder(oId);
        //修改库存
        int m = re.removeShsByPid(n);
		String mm = Integer.toString(m);
  		PrintWriter pw = resp.getWriter();
		pw.write(mm);
		
		
	}

}
